package com.jf.cloud.service.sysmanager.common.util;

public class EncodingUtil {
	
	/**
	 * 查询 当前汉字是什么编码
	 * @author ouyang 创建时间：2012-09-19 14:43:14
	 */
    public static String getEncoding(String str) {
        String encode = "ISO-8859-1";
        try {  
            if (str.equals(new String(str.getBytes(encode), encode))) {
                String s1 = encode;
                return s1;  
            }  
        } catch (Exception exception1) {
        }  
        encode = "UTF-8";
        try {  
            if (str.equals(new String(str.getBytes(encode), encode))) {
                String s2 = encode;
                return s2;  
            }  
        } catch (Exception exception2) {
        }  
        encode = "GBK";  
        try {  
            if (str.equals(new String(str.getBytes(encode), encode))) {
                String s3 = encode;
                return s3;  
            }  
        } catch (Exception exception3) {
        }  
        return "";  
    }  
    /**
     * 获取GBK的正常汉字 （自动转码）
     * @author ouyang 创建时间：2012-09-19 14:43:14
     */
    public static String getString(String str) {
    	String encode = "ISO-8859-1";
    	try {  
    		if (str.equals(new String(str.getBytes(encode), encode))) {
    			return new String(str.getBytes(encode), "GBK");
    		}  
    	    encode = "GBK";  
    		if (str.equals(new String(str.getBytes(encode), encode))) {
    			return str;    
    		}  
    		encode = "UTF-8";
      		if (str.equals(new String(str.getBytes(encode), encode))) {
      			return new String(str.getBytes(encode), "GBK");
      		}  
    	} catch (Exception exception3) {
    	}  
    	return "";  
    }  
}
